package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.po.OrderIdCardCostInfoPo;
import com.ymatou.iapi.trading.operate.parameter.req.QueryAnnualConsumeAmountReq;
import com.ymatou.iapi.trading.operate.service.QueryAnnualConsumeAmountCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.constant.ECode;

/**
 *  * 根据某个身份证的年度消费金额
 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_QueryAnnualConsumeAmount {
	private static QueryAnnualConsumeAmountReq afppbean;
	private static QueryAnnualConsumeAmountCall afppcall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("卖家申请补款");
	}

	@Before
	public void caseUp() {

		afppbean = new QueryAnnualConsumeAmountReq();
		afppcall = new QueryAnnualConsumeAmountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(afppcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_QueryAnnualConsumeAmount_001() {
		Logger.start(true, "根据用户身份证id，查询用户年底额度");
		try {

			DefaultWapper database = new DefaultWapper();

			OrderIdCardCostInfoPo orderIdCardCostInfoPo = database
					.getOrderIdCardCostInfo(null);

			afppbean.setIdCardNo(orderIdCardCostInfoPo.getIdCardNo());
			afppcall.setData(afppbean);

			afppcall.callService();

			// 创建订单	
			Logger.verifyEquals(ECode.SUCCESS, afppcall.getString("code"),
					"验证Code");

			DataUtil.verifyDecimalEquals(orderIdCardCostInfoPo.getAmount(),
					BigDecimal.valueOf((Double) afppcall.getData()
							.get("amount")), "验证Code");

			Logger.verifyEquals(true, afppcall.getData().getBoolean("success"),
					"验证success");

		} catch (Exception e) {

			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_QueryAnnualConsumeAmount_002() {
		Logger.start(true, "不存在的身份证");
		try {

			afppbean.setIdCardNo("ssss");
			afppcall.setData(afppbean);

			afppcall.callService();

			// 创建订单	
			Logger.verifyEquals(ECode.SUCCESS, afppcall.getString("code"),
					"验证Code");

			DataUtil.verifyDecimalEquals(BigDecimal.ZERO, afppcall.getData()
					.get("amount"), "验证Code");

			Logger.verifyEquals(true, afppcall.getData().getBoolean("success"),
					"验证success");

		} catch (Exception e) {

			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_QueryAnnualConsumeAmount_003() {
		Logger.start(true, "身份证为空字符串");
		try {

			afppbean.setIdCardNo("");
			afppcall.setData(afppbean);

			afppcall.callService();

			// 创建订单	
			Logger.verifyEquals(ECode.ERROR400, afppcall.getString("code"),
					"验证Code");

			Logger.verifyEquals("idCardNo:may not be empty", afppcall.getMsg(),
					"验证msg");

		} catch (Exception e) {

			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_QueryAnnualConsumeAmount_004() {
		Logger.start(true, "身份证为空");
		try {

			//afppbean.setIdCardNo("222");
			afppcall.setData(afppbean);

			afppcall.callService();

			// 创建订单	
			Logger.verifyEquals(ECode.ERROR400, afppcall.getString("code"),
					"验证Code");

			Logger.verifyEquals("idCardNo:may not be empty", afppcall.getMsg(),
					"验证msg");

		} catch (Exception e) {

			Logger.fail(e);
		}
	}
}
